
var 
  Monitor = require('./Monitor.class'),
  mm = require('./manager');







function createMonitor(mid, options){
  var monitor = new Monitor(mid, options);
  mm.regist(monitor);
  if(options.autoStart){
    monitor.status = 1;
    monitor.start();
  }
  return monitor;
}

function stopMonitor(mid){
  var monitor = mm.get(mid);
  if(!!monitor && monitor.status === 1){
    monitor.status = 0;
    monitor.stop();    
    return true;
  }else{
    return false;
  }

}

function startMonitor(mid){
  var monitor = mm.get(mid);
  if(!!monitor && monitor.status === 0){
    monitor.status = 1;
    monitor.start();    
    return true;
  }else{
    return false;
  } 
}

function getStatus(mid){
  var monitor = mm.get(mid);
  if(!!monitor){
    return {
      code:200,
      result: monitor.getStatus()
    };
  }else{
    return {
      code: 500,
      msg: 'No such monitor'
    };
  } 
}


// exports.createHTTP = createHTTPMonitor;
exports.status = getStatus;
exports.start = startMonitor;
exports.stop = stopMonitor;
exports.create = createMonitor;
